package com.tanhua.model.domain;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * @author Xiao
 * @version 1.0
 * @description 日志表实体类
 * @date 2021/11/5
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("tb_log")
public class Log implements Serializable {
    private static final long serialVersionUID = 1L;
    private Long id;    //id
    private Long userId;    //用户id
    private String logTime; //操作时间
    @TableField(exist = false)
    private String busId;   //业务id(动态或视频id)
    /**
     * 操作类型,
     * 0101为登录，0102为注册，
     * 0201为发动态，0202为浏览动态，0203为动态点赞，0204为动态喜欢，0205为评论，0206为动态取消点赞，0207为动态取消喜欢，
     * 0301为发小视频，0302为小视频点赞，0303为小视频取消点赞，0304为小视频评论
     */
    private String type;
    private String place = "长沙市岳麓区";   //登陆地点
    private String equipment = "红米NOTE9 Pro";   //登陆设备

    @TableField(fill = FieldFill.INSERT) //自动填充
    private Date created;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updated;

    public static Log init(Long userId, String logTime, String type, String busId) {
        Log log = new Log();
        log.setUserId(userId);
        log.setLogTime(logTime);
        log.setType(type);
        if (ObjectUtil.isNotEmpty(busId)) {
            log.setBusId(busId);
        }
        return log;
    }
}
